//package com.newcapec.modules.terminal.mqtt;
//
//import lombok.extern.slf4j.Slf4j;
//import org.eclipse.paho.client.mqttv3.MqttClient;
//import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
//import org.eclipse.paho.client.mqttv3.MqttException;
//import org.eclipse.paho.client.mqttv3.MqttMessage;
//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//
//@Component
//@Slf4j
//public class InitMqtt {
//    @Value("${mqtt.clientId}")
//    private String mqttClientId;
//    @Value(("${mqtt.username}"))
//    private String mqttUserName;
//    @Value("${mqtt.password}")
//    private String mqttPasswod;
//    @Value("${mqtt.url}")
//    private String mqttUrl;
//    @Value("${mqtt.topic}")
//    private String mqttTopic;
//
//    @Autowired
//    private OnMessageCallback onMessageCallback;
//
//
//    @PostConstruct
//    public void init(){
//        log.info(mqttClientId);
//        log.info(mqttUserName);
//        log.info(mqttPasswod);
//        log.info(mqttUrl);
//        MemoryPersistence persistence = new MemoryPersistence();
//
//        try {
//            MqttClient client = new MqttClient(mqttUrl, mqttClientId, persistence);
//
//            // MQTT 连接选项
//            MqttConnectOptions connOpts = new MqttConnectOptions();
//            connOpts.setUserName(mqttUserName);
//            connOpts.setPassword(mqttPasswod.toCharArray());
//            // 保留会话
//            connOpts.setCleanSession(true);
//
//            // 设置回调
//            client.setCallback(onMessageCallback);
//
//            // 建立连接
//
//            client.connect(connOpts);
//
//
//
//            // 订阅
//            client.subscribe(mqttTopic,2);
//
//            // 消息发布所需参数
///*            MqttMessage message = new MqttMessage(content.getBytes());
//            message.setQos(qos);
//            client.publish(pubTopic, message);
//            System.out.println("Message published");*/
//
///*            client.disconnect();
//            System.out.println("Disconnected");
//            client.close();
//            System.exit(0);*/
//        } catch (MqttException me) {
//            System.out.println("reason " + me.getReasonCode());
//            System.out.println("msg " + me.getMessage());
//            System.out.println("loc " + me.getLocalizedMessage());
//            System.out.println("cause " + me.getCause());
//            System.out.println("excep " + me);
//            me.printStackTrace();
//        }
//    }
//}
